<!DOCTYPE html>
<html>  
<head>  
<meta charset="UTF-8">  
<title>LED测试</title>  
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.js"></script>

<script language="javascript">
    var cnt = 0;
	function doLoad()
	{
		cnt++;
		//every five seconds to repeat self
       	setTimeout("doLoad()",1000*1);
		var httpRequest = new XMLHttpRequest();
        httpRequest.open('GET', '/LED', true);
        httpRequest.send();

        httpRequest.onreadystatechange = function () {
            if (httpRequest.readyState == 4 && httpRequest.status == 200) {
                var led_state = httpRequest.responseText;
                //console.log(led_state);
				document.getElementById("LED").innerHTML = led_state;
				
            }
        };
	}
</script>
<script>
	function Led_Switch(s)
	{
		var httpRequest = new XMLHttpRequest();
        httpRequest.open('POST', '/Switch', true);
        httpRequest.send(s);

        httpRequest.onreadystatechange = function () {
            if (httpRequest.readyState == 4 && httpRequest.status == 200) {
                var led_state = httpRequest.responseText;
                //console.log(led_state);
				document.getElementById("LED").innerHTML = led_state;
            }
        };
	}
</script>

</head>

<body onLoad="doLoad();">
<div style=" text-align:center;"><br /><br /><br /><br /><br />LED状态:<a></a></div>
<div id="LED" style=" text-align:center;"></div>

<div style=" text-align:center;">
<button onclick='Led_Switch("LED_ON")'>开关 开</button>
</div>
<div style=" text-align:center;">
<button onclick='Led_Switch("LED_OFF")'>开关 关</button>
</div>

</body>
</html>
